package com.longdaji.decoration.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.longdaji.decoration.R;
import com.longdaji.decoration.utils.ViewUtils;

public class PayDialog extends Dialog {

    private Callback mCallBack;
    private Context mContext;
    private ImageView mIvCancle;
    private Button mBtnSubmit;
    private LinearLayout mLlytAlipay;
    private CheckBox mCbAlipay;

    public PayDialog(Context context) {
        //重点实现R.style.DialogStyle 动画效果
        this(context, R.style.BottomDialogStyle);
        mContext = context;

    }

    public PayDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public void setData(Callback callback) {
        this.mCallBack = callback;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_pay);
        // 拿到Dialog的Window, 修改Window的属性
        Window window = getWindow();
        window.getDecorView().setPadding(0, 0, 0, 0);
        // 获取Window的LayoutParams
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.width = WindowManager.LayoutParams.MATCH_PARENT;
        attributes.height = ViewUtils.getScreenHeightPixels(mContext) * 1 / 2;
        attributes.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
        // 一定要重新设置, 才能生效
        window.setAttributes(attributes);
        initView();
    }

    private void initView() {
        mIvCancle = findViewById(R.id.iv_cancle);
        mBtnSubmit = findViewById(R.id.btn_submit);
        mLlytAlipay = findViewById(R.id.llyt_alipay);
        mCbAlipay = findViewById(R.id.cb_alipay);
        mIvCancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCallBack.onCancle();
                dismiss();
            }
        });
        mBtnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCallBack.onSubmit();
                dismiss();
            }
        });
    }

    public interface Callback {
        void onSubmit();

        void onCancle();
    }
}
